﻿using System;
using HNAC.Weixin.MP.Context;
using HNAC.Weixin.MP.Entities;
using HNAC.Weixin.MP.MessageHandlers;
using System.Data;
using System.Collections.Generic;
using HNAC.MP.Model;
using HNAC.MP.Bll;
using HNAC.MP.Common;

namespace HNAC.Weixin.CommonService.CustomMessageHandler
{
    /// <summary>
    /// 自定义MessageHandler
    /// </summary>
    public partial class CustomMessageHandler : MessageHandler<MessageContext>
    {
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            var responseMessage = base.CreateResponseMessage<ResponseMessageNews>();
            responseMessage.Articles = new System.Collections.Generic.List<Article>();
            string sqltext = string.Empty;
            //当前用户信息
            bool isLogin = false;
            string hznetuser, hznetpwd = string.Empty, currentstaionid = string.Empty, currentstationname = string.Empty;
            UserOperationLevel oplevel = UserOperationLevel.None;
            int currentpage = 1;
            DataSet dsuser = null;
            BUser Buser = new BUser();
            MUser Muser;
            Muser = Buser.GetModel(requestMessage.FromUserName);
            #region 从数据库中对比，确定用户是否已经有绑定关系
            try
            {
               // sqltext = "select * from user where name='" + requestMessage.FromUserName + "'";
               // dsuser = SQLiteHelper.ExecuteDataset(sqltext, GlobalVar.ShareDBConnStr);
                if (Muser != null)
                {
                    if (!string.IsNullOrEmpty(Muser.hznetuser))
                    {
                        isLogin = true;
                    }
                }
            }
            catch (Exception)
            {
                isLogin = false;
            }
            #endregion

            string groupid = string.Empty;
            Article arc = new Article();
            #region 已登录的处理流程
            if (isLogin)
            {
                int? levelid = Muser.oplevelid;
                oplevel = (UserOperationLevel)levelid;
                List<Article> arcs = new List<Article>();
                // arcs.Add(arc);
                hznetuser = Muser.hznetuser;
                hznetpwd = Muser.hzpwd;
                //菜单点击，需要跟创建菜单时的Key匹配
                switch (requestMessage.EventKey)
                {
                    case "V1001_Loginout":
                        {
                            UserLogin.GetLogoutArc(requestMessage.FromUserName);
                            responseMessage.Articles.Add(arc);                           
                        }
                        break;
                    case "V1001_Station":
                        {
                            string str = string.Empty;
                            if (StationsBussiness.GetStations2(requestMessage.FromUserName, hznetuser, ref str, hznetpwd))
                            {
                                arc.Title = "站点管理";
                                arc.PicUrl = GlobalVar.LogoImageUrl;
                            }
                            else
                            {
                                arc.Title = "获取站点信息失败";
                                arc.PicUrl = GlobalVar.ErrorImageUrl;
                            }
                            arc.Description = str;
                            responseMessage.Articles.Add(arc);

                            sqltext = "update user set oplevelid='1' where name='" + requestMessage.FromUserName + "'";
                            SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                        }
                        break;
                    case "V1011_Real":
                        {
                            currentstaionid = dsuser.Tables[0].Rows[0]["stationno"].ToString().Trim();
                            currentstationname = dsuser.Tables[0].Rows[0]["stationname"].ToString().Trim();
                            if (string.IsNullOrEmpty(currentstaionid) || string.IsNullOrEmpty(currentstationname))
                            {
                                responseMessage.Articles.Clear();
                                arc.PicUrl = GlobalVar.ErrorImageUrl;
                                arc.Title = "站点管理";
                                arc.Description = "请先进入站点再查看数据\n" + StationsBussiness.GetStations(requestMessage.FromUserName, hznetuser, hznetpwd);
                                responseMessage.Articles.Add(arc);
                            }
                            else
                            {
                                arc.Title = currentstationname + "-->实时遥测";
                                arc.PicUrl = GlobalVar.LogoImageUrl;
                                arc.Description = "请选择你要查看的数据";
                                responseMessage.Articles.Add(arc);
                                responseMessage.Articles.Add(new Article()
                                {
                                    Title = "请点击你需要查看的数据\n上一页请回复997\n下一页请回复998\n当前为第1页,",//总计" + totalpage.ToString() + "页",
                                    PicUrl = "",
                                });
                                StationsBussiness.GetRealDataFilesPic(requestMessage.FromUserName, currentstaionid, currentstationname);
                                //arc.Description = StationsBussiness.GetRealDataFiles(requestMessage.FromUserName, cachedata.StationIdandName[cachedata.StationNo]);
                                arcs.AddRange(StationsBussiness.GetRealDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                responseMessage.Articles.AddRange(arcs);
                                responseMessage.Articles[1].Title += "总计" + StationsBussiness.GetRealDataFilePageCount(requestMessage.FromUserName, currentstaionid).ToString() + "页";
                                sqltext = "update user set oplevelid='2', pageno='1' where name='" + requestMessage.FromUserName + "'";
                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                            }
                        }
                        break;
                    case "V1011_History":
                        {
                            currentstaionid = dsuser.Tables[0].Rows[0]["stationno"].ToString().Trim();
                            currentstationname = dsuser.Tables[0].Rows[0]["stationname"].ToString().Trim();
                            if (string.IsNullOrEmpty(currentstaionid) || string.IsNullOrEmpty(currentstationname))
                            {
                                responseMessage.Articles.Clear();
                                arc.PicUrl = GlobalVar.ErrorImageUrl;
                                arc.Title = "站点管理";
                                arc.Description = "请先进入站点再查看数据\n" + StationsBussiness.GetStations(requestMessage.FromUserName, hznetuser, hznetpwd);
                                responseMessage.Articles.Add(arc);
                            }
                            else
                            {
                                arc.Title = currentstationname + "-->历史数据曲线";
                                arc.PicUrl = GlobalVar.LogoImageUrl;
                                arc.Description = "请选择你要查看的数据";
                                responseMessage.Articles.Add(arc);
                                responseMessage.Articles.Add(new Article()
                                {
                                    Title = "请点击你需要查看的数据\n上一页请回复997\n下一页请回复998\n当前为第1页,",
                                    PicUrl = "",
                                });
                                //先将数据存入数据库，再读取
                                StationsBussiness.GetHistoryDataFilesPic(requestMessage.FromUserName, currentstaionid, currentstationname);
                                arcs.AddRange(StationsBussiness.GetHistoryDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                responseMessage.Articles[1].Title += "总计" + StationsBussiness.GetHistoryDataFilePageCount(requestMessage.FromUserName, currentstaionid).ToString() + "页";
                                responseMessage.Articles.AddRange(arcs);
                                sqltext = "update user set oplevelid='3',pageno='1' where name='" + requestMessage.FromUserName + "'";
                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                            }
                        }
                        break;
                    case "V1011_Alert"://告警
                        {
                            currentstaionid = dsuser.Tables[0].Rows[0]["stationno"].ToString().Trim();
                            currentstationname = dsuser.Tables[0].Rows[0]["stationname"].ToString().Trim();
                            if (string.IsNullOrEmpty(currentstaionid) || string.IsNullOrEmpty(currentstationname))
                            {
                                responseMessage.Articles.Clear();
                                arc.PicUrl = GlobalVar.ErrorImageUrl;
                                arc.Title = "站点管理";
                                arc.Description = "请先进入站点再查看数据\n" + StationsBussiness.GetStations(requestMessage.FromUserName, hznetuser, hznetpwd);
                                responseMessage.Articles.Add(arc);
                            }
                            else
                            {
                                arc.Title = currentstationname + "-->历史告警";
                                arc.PicUrl = GlobalVar.LogoImageUrl;
                                arc.Description = "请选择你要查看的数据";
                                responseMessage.Articles.Add(arc);
                                responseMessage.Articles.Add(new Article()
                                {
                                    //Title = "请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999",
                                    Title = "请点击你需要查看的数据\n",
                                    PicUrl = "",
                                });
                                arcs.AddRange(StationsBussiness.GetAlertDataFilesPic(requestMessage.FromUserName, currentstaionid, currentstationname));
                                responseMessage.Articles.AddRange(arcs);
                                sqltext = "update user set oplevelid='4' , pageno='1' where name='" + requestMessage.FromUserName + "'";
                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                            }
                        }
                        break;
                    case "V1001_Front":
                        {
                            int totalpage = 0;
                            currentstaionid = dsuser.Tables[0].Rows[0]["stationno"].ToString().Trim();
                            currentstationname = dsuser.Tables[0].Rows[0]["stationname"].ToString().Trim();
                            if (string.IsNullOrEmpty(currentstaionid) || string.IsNullOrEmpty(currentstationname))
                            {
                                //站号为空不处理
                            }
                            else
                            {
                                switch (oplevel)
                                {
                                    //只处理查看遥测数据和历史数据的翻页动作
                                    case UserOperationLevel.HisYcYxView:
                                        {
                                            totalpage = StationsBussiness.GetHistoryDataFilePageCount(requestMessage.FromUserName, currentstaionid);
                                            if (currentpage == 1)
                                            {
                                                responseMessage.Articles.Clear();
                                                arc.Title = currentstationname + "-->历史数据曲线";
                                                arc.PicUrl = GlobalVar.ErrorImageUrl;
                                                arc.Description = "请选择你要查看的数据";
                                                responseMessage.Articles.Add(arc);
                                                responseMessage.Articles.Add(new Article()
                                                {
                                                    Title = "回复有误!,当前已经是第一页.\n请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + totalpage.ToString() + "页",
                                                    PicUrl = "",
                                                });
                                                arcs.AddRange(StationsBussiness.GetHistoryDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                responseMessage.Articles.AddRange(arcs);
                                                sqltext = "update user set oplevelid='3' , pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                            }
                                            else
                                            {
                                                currentpage--;
                                                responseMessage.Articles.Clear();
                                                arc.Title = currentstationname + "-->历史数据曲线";
                                                arc.PicUrl = GlobalVar.LogoImageUrl;
                                                arc.Description = "请选择你要查看的数据";
                                                responseMessage.Articles.Add(arc);
                                                responseMessage.Articles.Add(new Article()
                                                {
                                                    Title = "请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + totalpage.ToString() + "页",
                                                    PicUrl = "",
                                                });
                                                arcs.AddRange(StationsBussiness.GetHistoryDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                responseMessage.Articles.AddRange(arcs);
                                                sqltext = "update user set oplevelid='3' , pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                            }
                                        }
                                        break;
                                    case UserOperationLevel.RealYcYxView:
                                        {
                                            if (string.IsNullOrEmpty(currentstaionid) || string.IsNullOrEmpty(currentstationname))
                                            {
                                                //站号为空不处理
                                            }
                                            else
                                            {
                                                totalpage = StationsBussiness.GetRealDataFilePageCount(requestMessage.FromUserName, currentstaionid);
                                                if (currentpage == 1)
                                                {
                                                    responseMessage.Articles.Clear();
                                                    arc.Title = currentstationname + "-->查看实时遥测";
                                                    arc.PicUrl = GlobalVar.ErrorImageUrl;
                                                    arc.Description = "请选择你要查看的数据";
                                                    responseMessage.Articles.Add(arc);
                                                    responseMessage.Articles.Add(new Article()
                                                    {
                                                        Title = "回复有误!,当前已经是第一页.\n请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + totalpage.ToString() + "页",
                                                        PicUrl = "",
                                                    });
                                                    arcs.AddRange(StationsBussiness.GetRealDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                    responseMessage.Articles.AddRange(arcs);
                                                    sqltext = "update user set oplevelid='2' , pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                    SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                                }
                                                else
                                                {
                                                    currentpage--;
                                                    responseMessage.Articles.Clear();
                                                    arc.Title = currentstationname + "-->查看实时遥测";
                                                    arc.PicUrl = GlobalVar.LogoImageUrl;
                                                    arc.Description = "请选择你要查看的数据";
                                                    responseMessage.Articles.Add(arc);
                                                    responseMessage.Articles.Add(new Article()
                                                    {
                                                        Title = "请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + StationsBussiness.GetRealDataFilePageCount(requestMessage.FromUserName, currentstaionid).ToString() + "页",
                                                        PicUrl = "",
                                                    });
                                                    arcs.AddRange(StationsBussiness.GetRealDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                    responseMessage.Articles.AddRange(arcs);
                                                    sqltext = "update user set oplevelid='2', pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                    SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                                }
                                            }
                                        }
                                        break;
                                    default:
                                        //其他情况不返回数据
                                        break;
                                }
                            }
                        }
                        break;
                    case "V1001_Next":
                        {
                            int totalpage = 0;
                            currentstaionid = dsuser.Tables[0].Rows[0]["stationno"].ToString().Trim();
                            currentstationname = dsuser.Tables[0].Rows[0]["stationname"].ToString().Trim();
                            if (string.IsNullOrEmpty(currentstaionid) || string.IsNullOrEmpty(currentstationname))
                            {
   //
                            }
                            else
                            {
                                switch (oplevel)
                                {
                                    //只处理查看遥测数据和历史数据的翻页动作
                                    case UserOperationLevel.HisYcYxView:
                                        {
                                            totalpage = StationsBussiness.GetHistoryDataFilePageCount(requestMessage.FromUserName, currentstaionid);
                                            if (currentpage == totalpage)
                                            {
                                                responseMessage.Articles.Clear();
                                                arc.Title = currentstationname + "-->历史数据曲线";
                                                arc.PicUrl = GlobalVar.ErrorImageUrl;
                                                arc.Description = "请选择你要查看的数据";
                                                responseMessage.Articles.Add(arc);
                                                responseMessage.Articles.Add(new Article()
                                                {
                                                    Title = "回复有误!,当前已经是最后一页.\n请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + totalpage.ToString() + "页",
                                                    PicUrl = "",
                                                });
                                                arcs.AddRange(StationsBussiness.GetHistoryDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                responseMessage.Articles.AddRange(arcs);
                                                sqltext = "update user set oplevelid='3' , pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                            }
                                            else
                                            {
                                                currentpage++;
                                                responseMessage.Articles.Clear();
                                                arc.Title = currentstationname + "-->历史数据曲线";
                                                arc.PicUrl = GlobalVar.LogoImageUrl;
                                                arc.Description = "请选择你要查看的数据";
                                                responseMessage.Articles.Add(arc);
                                                responseMessage.Articles.Add(new Article()
                                                {
                                                    Title = "请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + totalpage.ToString() + "页",
                                                    PicUrl = "",
                                                });
                                                arcs.AddRange(StationsBussiness.GetHistoryDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                responseMessage.Articles.AddRange(arcs);
                                                sqltext = "update user set oplevelid='3' , pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                            }
                                        }
                                        break;
                                    case UserOperationLevel.RealYcYxView:
                                        {
                                            {
                                                totalpage = StationsBussiness.GetRealDataFilePageCount(requestMessage.FromUserName, currentstaionid);
                                                if (currentpage == totalpage)
                                                {
                                                    responseMessage.Articles.Clear();
                                                    arc.Title = currentstationname + "-->查看实时遥测";
                                                    arc.PicUrl = GlobalVar.ErrorImageUrl;
                                                    arc.Description = "请选择你要查看的数据";
                                                    responseMessage.Articles.Add(arc);
                                                    responseMessage.Articles.Add(new Article()
                                                    {
                                                        Title = "回复有误!,当前已经是最后一页.\n请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + totalpage.ToString() + "页",
                                                        PicUrl = "",
                                                    });
                                                    arcs.AddRange(StationsBussiness.GetRealDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                    responseMessage.Articles.AddRange(arcs);
                                                    sqltext = "update user set oplevelid='2' , pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                    SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                                }
                                                else
                                                {
                                                    currentpage++;
                                                    responseMessage.Articles.Clear();
                                                    arc.Title = currentstationname + "-->查看实时遥测";
                                                    arc.PicUrl = GlobalVar.LogoImageUrl;
                                                    arc.Description = "请选择你要查看的数据";
                                                    responseMessage.Articles.Add(arc);
                                                    responseMessage.Articles.Add(new Article()
                                                    {
                                                        Title = "请点击你需要查看的数据\n如需退出登录请回复0\n返回上级菜单请回复999\n上一页请回复997\n下一页请回复998\n当前为第" + currentpage.ToString() + "页,总计" + StationsBussiness.GetRealDataFilePageCount(requestMessage.FromUserName, currentstaionid).ToString() + "页",
                                                        PicUrl = "",
                                                    });
                                                    arcs.AddRange(StationsBussiness.GetRealDataFilesPicBypageNo(requestMessage.FromUserName, currentstaionid, currentpage));
                                                    responseMessage.Articles.AddRange(arcs);
                                                    sqltext = "update user set oplevelid='2', pageno='" + currentpage.ToString() + "' where name='" + requestMessage.FromUserName + "'";
                                                    SQLiteHelper.ExecuteNonQuery(sqltext, GlobalVar.ShareDBConnStr);
                                                }
                                            }
                                        }
                                        break;
                                    default:
                                        //其他情况不返回数据
                                        break;
                                }
                            }
                        }
                        break;
                }
            }
            #endregion
            else
            {
                responseMessage.Articles = new System.Collections.Generic.List<Article>();
                arc.Title = "欢迎您进入HzNet微信平台" + GlobalVar.CurrentVersion;
                arc.Description = "请先登录，登录格式为：用户名，密码。用户名和密码用逗号间隔开。";
                //arc.PicUrl = ConstantVar.SERVERPATH + "Resource/Images/loginimg.jpg";
                arc.PicUrl = GlobalVar.LogoImageUrl;
                responseMessage.Articles.Add(arc);
            }
            return responseMessage;
        }

        public override IResponseMessageBase OnEvent_EnterRequest(RequestMessageEvent_Enter requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            responseMessage.Content = "您刚才发送了ENTER事件请求。";
            return responseMessage;
        }

        public override IResponseMessageBase OnEvent_LocationRequest(RequestMessageEvent_Location requestMessage)
        {
            throw new Exception("暂不可用");
        }

        /// <summary>
        /// 订阅（关注）事件
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageNews>(requestMessage);

            #region
            //获取HNAC.Weixin.MP.dll版本信息
//            var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/HNAC.Weixin.MP.dll"));
//            var version = string.Format("{0}.{1}", fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart);
//            responseMessage.Content = string.Format(
//@"欢迎关注【HNAC.Weixin.MP 微信公众平台SDK】，当前运行版本：v{0}。
//您可以发送【文字】【位置】【图片】【语音】等不同类型的信息，查看不同格式的回复。
//
//SDK官方地址：http://weixin.senparc.com
//源代码及Demo下载地址：https://github.com/JeffreySu/WeiXinMPSDK",
            //                version);
            #endregion
            //加入缓存表
            //AppCommon.Instance.Caches[requestMessage.FromUserName] = new UserCacheData();

            #region
            //UserCacheData cacheUser = new UserCacheData();
            //ServerCache.SetCache(requestMessage.FromUserName, cacheUser);
            //string sqltext = "SELECT * FROM TWxUserBind WHERE wxUser= '" + requestMessage.FromUserName + "'";
            //DbHelperSQL.DBConnStr = GlobalVar.ShareDBConnStr;
            //DataSet ds = DbHelperSQL.Query(sqltext);
            //if (ds.Tables[0].Rows.Count == 1)
            //{
            //    sqltext = "UPDATE TWxUserBind set hzUserid = '' WHERE wxUser = '" + requestMessage.FromUserName + "'";
            //    DbHelperSQL.ExecuteSql(sqltext);
            //}
            //else
            //{
            //    sqltext = "INSERT INTO TWxUserBind (wxUser) values( '" + requestMessage.FromUserName + "')";
            //    DbHelperSQL.ExecuteSql(sqltext);
            //}
            #endregion
            
            responseMessage.Articles = new System.Collections.Generic.List<Article>();
            responseMessage.Articles.Add(StationsBussiness.GetLoginURL(requestMessage.FromUserName, requestMessage.Signature, requestMessage.TimeStamp, requestMessage.Nonce));
            return responseMessage;
        }

        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息，所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定，消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            #region
            //string sqltext = "DELETE FROM TWxUserBind WHERE wxUser = '" + requestMessage.FromUserName + "'";
            //DbHelperSQL.DBConnStr = GlobalVar.ShareDBConnStr;
            //DbHelperSQL.ExecuteSql(sqltext);
            //ServerCache.DeleteCache(requestMessage.FromUserName);
            #endregion
            //从缓存表中剔除
           // AppCommon.Instance.Caches.CustomData.Remove(requestMessage.FromUserName);
            UserLogin.LoginOut(requestMessage.FromUserName);
            if (StationsBussiness.ExistTable(requestMessage.FromUserName))
            {
                string sql = "drop table " + requestMessage.FromUserName;
                SQLiteHelper.ExecuteNonQuery(sql, GlobalVar.ShareDBConnStr);
            }
            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            //responseMessage.Content = "有空再来";
            return responseMessage;
        }

    }
}